<cfoutput>
&lt;cfcomponent displayname="ModelFactory" hint="Returns a model whose properties are populated either from GET or POST"&gt;
	&lt;cffunction name="init"&gt;
		&lt;cfreturn this /&gt;
	&lt;/cffunction&gt;
	&lt;cffunction name="setModelFromURL"&gt;
		&lt;cfargument name="modelName" required="true" /&gt;
		&lt;cfargument name="modelValueList" hint="Send in the model values (generally from URL) in the form m1_id/1/m2_id/2" /&gt;
		&lt;cfset var Model = createObject("component","##arguments.modelName##") /&gt;
		&lt;cfset var temp = StructNew() /&gt;
			
		&lt;cfif listLen(arguments.modelValueList,'/') GT 1&gt;
			&lt;cfloop from="1" to="##listLen(arguments.modelValueList,'/')##" index="i" step="2"&gt;
				&lt;cfset temp["##modelName##"][listGetAt(arguments.modelValueList,i,'/')]["value"] = listGetAt(arguments.modelValueList,i+1,'/') /&gt;	
			&lt;/cfloop&gt;
		&lt;cfelse&gt;
			&lt;cfset temp = deserializeJSON(Model.properties) /&gt;
			&lt;cfloop collection="##temp[arguments.modelName]##" item="column_name"&gt;
				&lt;cfif structKeyExists(temp["##arguments.modelName##"]["##column_name##"], 'key') AND temp["##arguments.modelName##"]["##column_name##"]['key'] EQ 'primary'&gt;
					&lt;cfset temp[arguments.modelName][column_name]['value'] = arguments.modelValueList&gt;
				&lt;/cfif&gt;
			&lt;/cfloop&gt;
		&lt;/cfif&gt;
		
		&lt;cfset Model.setValues(temp) /&gt;		
		&lt;cfreturn Model /&gt;
	&lt;/cffunction&gt;
	&lt;cffunction access="public" returntype="any" name="setModelFromForm"&gt;
		&lt;cfargument name="ModelName" type="String" required="true" /&gt;
		&lt;cfargument name="SubmittedForm" type="Struct" required="true" /&gt;
		&lt;cfset var Model = createObject("component", "##arguments.modelname##")&gt;
		&lt;cfset var temp = StructNew() /&gt;
		&lt;cfloop collection="##arguments.SubmittedForm##" item="form_item"&gt;		
			&lt;cfset temp["##modelName##"]["##form_item##"]["value"] = "##arguments.SubmittedForm[form_item]##" /&gt;
		&lt;/cfloop&gt;
		&lt;cfset Model.setValues(temp) /&gt;
		&lt;cfreturn Model /&gt;
	&lt;/cffunction&gt;
&lt;/cfcomponent&gt;
</cfoutput>